from flask import Blueprint, request, jsonify, current_app
import logging, os
from utils import common
mj_bp = Blueprint('mj', __name__, url_prefix='/mj')

# mj_bp = common.add_url_to_bp(os.path.dirname(__file__), mj_bp)
@mj_bp.route('jobs', methods=['GET'])
def jobs():
    params = dict(request.args)
    result =  current_app.config['DB'].get_mj_jobs(params)

    ## 变成字典
    rdata = list()
    for item in result:
        rdata.append(
            {
                'prompt': item[7],
                'img_url': item[8]
            }
        )

    return jsonify({'code':0, 'data':rdata})


@mj_bp.record
def log(app):
    logging.info('register mj blueprint')
